<template>
{{#if ctrl.psSysPFPlugin}}
  {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
{{else}}
    <AppList
        :id="controlID"
        :class="classNames"
        :items="store.data"
        :selections="store.selections"
        :totalRecord="store.totalRecord"
  {{#if ctrl.emptyText}}
        emptyText="{{ctrl.emptyText}}"
  {{/if}}
  {{#if ctrl.emptyTextPSLanguageRes}}
        emptyTextPSLanguageRes="{{ctrl.emptyTextPSLanguageRes.lanResTag}}"
  {{/if}}          
        @item-click="handleItemClick"
        @item-db-click="handleItemDbClick"
        @selection-change="handleSelectionChange"
        @load-more="handleLoadMore"
        @item-action-click="(logic: any, data: IParam, event: MouseEvent) => handleActionClick(controller, logic, data, event)">
        {{#if ctrl.itemPSLayoutPanel}}
        <template #default="{ item }">
            {{> @macro/widgets/panel-detail/panel.hbs ctrl=ctrl.itemPSLayoutPanel props=":isLoadDefault='true'
            :data='item'"}}
        </template>
        {{/if}}
    </AppList>
{{/if}}
</template>
<script setup lang="ts">
// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@LIST}}-list/\{{ctrls@LIST}}-list.vue.hbs生成
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
import { AppList } from '@components/widgets/list';
import { ICtrlDataAction, IContext, IParam, ListActionType, IListAbility, IListControllerParams, IListStore, ListController, createUUID, ILoadingHelper, IViewCtx, IListController, IViewLogicInput } from '@/core';
{{#if ctrl.itemPSLayoutPanel}}
import {{ctrl.itemPSLayoutPanel.codeName}}Panel from '@widgets/{{spinalCase appEntity.codeName}}/{{spinalCase ctrl.itemPSLayoutPanel.codeName}}-panel/{{spinalCase ctrl.itemPSLayoutPanel.codeName}}-panel.vue';
{{/if}}
import { useNavParamsBind, getCtrlClassNames, useEventBind, handleActionClick, {{#if ctrl.itemPSLayoutPanel}}handleCtrlInit, handleCtrlAction, handleCtrlDestroy,{{/if}} } from '@/hooks/use-ctrl';
import { {{pascalCase ctrl.name}}ControlVO } from './{{spinalCase ctrl.codeName}}-list-vo';
import { model } from "./{{spinalCase ctrl.codeName}}-list-model";
import ListService from "@/core/modules/ctrl-service/list-service";
{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    actions: ICtrlDataAction;
    singleSelect?: boolean;
    rowActiveMode?: 0 | 1 | 2;
    selectFirstDefault?: boolean;
    "
    propsDefault="singleSelect: false,
    rowActiveMode: 2
    "
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="ListActionType" ability="IListAbility"}}

//  部件样式名
const classNames = computed(() => {
  return getCtrlClassNames(model, props);
});

const controlID = createUUID();
const params: IListControllerParams<ListActionType, IListAbility> = {
    name: props.name,
    model,
    evt,
    controlID,
    pLoadingHelper: props.pLoadingHelper,
    rowActiveMode: props.rowActiveMode,
    actions: props.actions,
    singleSelect: props.singleSelect,
    selectFirstDefault: props.selectFirstDefault,
    ctrlService: new ListService<{{pascalCase ctrl.name}}ControlVO>({{pascalCase ctrl.name}}ControlVO, model.entityCodeName),
    openView: props.openView,
    newView: props.newView,
    closeView: props.closeView,
    pViewCtx: props.pViewCtx,
    handler: (data: IListStore) => { return reactive(data) }
};

{{> @macro/common/controller.hbs name="ctrl" IController="IListController" store="IListStore" ability="IListAbility" controller="ListController"}}

const handleItemClick = (row: IParam, event: MouseEvent) => {
    controller.handleItemClick(row, event);
}

const handleItemDbClick = (row: IParam, event: MouseEvent) => {
    controller.handleItemDbClick(row, event);
}

const handleSelectionChange = (selections: IParam[]) => {
    controller.handleSelectionChange(selections);
}

const handleLoadMore = () => {
    controller.loadMore();
}
</script>